proc compplace (shiplen : int, shipid : int)
    loop
	var placex, placey, movedir, placexend, placeyend, baddir : int
	placex := Rand.Int (1, 10)
	placey := Rand.Int (1, 10)
	movedir := Rand.Int (1, 4)
	baddir := 0
	%shiplen := 5
	%putar
	if movedir = 1 then
	    if placex + shiplen < 11 and placex + shiplen > 0 then
		for i : placex .. (placex + (shiplen - 1))
		    if comploc (i, placey) = 1 then
			baddir := 1
		    end if
		    if comploc (placex, placey) = 1 then
			baddir := 1
		    end if

		end for
		if baddir = 0 then
		    for i : placex .. (placex + (shiplen - 1))
			comploc (i, placey) := 1
			%Draw.FillOval (((i - 1) * 20) + 10, ((placey - 1) * 20) + 10, 10, 10, black) % This will draw a circle where the user has clicked
			compships (shipid).startx := placex
			compships (shipid).starty := placey
			compships (shipid).endy := placey
			compships (shipid).endx := placex + (shiplen - 1)
			compships (shipid).mode := 1
		    end for
		    exit
		end if
	    else
		baddir := 1
	    end if
	end if

	if movedir = 2 then
	    if placex - shiplen < 11 and placex - shiplen > 0 then
		for decreasing i : placex .. (placex - (shiplen - 1))
		    %                    putar
		    if comploc (i, placey) = 1 then
			baddir := 1
		    end if
		    if comploc (placex, placey) = 1 then
			baddir := 1
		    end if
		end for
		if baddir = 0 then
		    for decreasing i : placex .. (placex - (shiplen - 1))
			comploc (i, placey) := 1
			%Draw.FillOval (((i - 1) * 20) + 10, ((placey - 1) * 20) + 10, 10, 10, black) % This will draw a circle where the user has clicked
			compships (shipid).startx := placex
			compships (shipid).starty := placey
			compships (shipid).endy := placey
			compships (shipid).endx := placex - (shiplen - 1)
			compships (shipid).mode := 2
		    end for
		    exit
		end if
	    else
		baddir := 1
	    end if
	end if

	if movedir = 3 then
	    if placey + shiplen < 11 and placey + shiplen > 0 then
		for i : placey .. (placey + (shiplen - 1))
		    %                    putar
		    if comploc (placex, i) = 1 then
			baddir := 1
		    end if
		    if comploc (placex, placey) = 1 then
			baddir := 1
		    end if
		end for
		if baddir = 0 then
		    for i : placey .. (placey + (shiplen - 1))
			comploc (placex, i) := 1
			%Draw.FillOval (((placex - 1) * 20) + 10, ((i - 1) * 20) + 10, 10, 10, black) % This will draw a circle where the user has clicked
			compships (shipid).startx := placex
			compships (shipid).starty := placey
			compships (shipid).endy := placey + (shiplen - 1)
			compships (shipid).endx := placex
			compships (shipid).mode := 3
		    end for
		    exit
		end if
	    else
		baddir := 1
	    end if
	end if

	if movedir = 4 then
	    if placey - shiplen < 11 and placey - shiplen > 0 then
		for decreasing i : placey .. (placey - (shiplen - 1))
		    if comploc (placex, i) = 1 then
			baddir := 1
		    end if
		    if comploc (placex, placey) = 1 then
			baddir := 1
		    end if
		end for
		if baddir = 0 then
		    for decreasing i : placey .. (placey - (shiplen - 1))
			comploc (placex, i) := 1
			%Draw.FillOval (((placex - 1) * 20) + 10, ((i - 1) * 20) + 10, 10, 10, black)
			compships (shipid).startx := placex
			compships (shipid).starty := placey
			compships (shipid).endy := placey - (shiplen - 1)
			compships (shipid).endx := placex
			compships (shipid).mode := 4
		    end for
		    exit
		end if
	    else
		baddir := 1
	    end if
	end if

    end loop
end compplace
